package com.tools.sqlmaker.make.impl;

import com.tools.sqlmaker.entry.OrgInfo;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: zhoubin
 * @date: 2023/9/7
 */
public class MqConfMaker extends GatewayBaseMaker {

    public MqConfMaker(OrgInfo info) {
        super(info);
    }

    @Override
    public List<Map<String, Object>> getParamList() {
        OrgInfo info = getOrgInfo();
        List<String> sysQmCodeList = getSysQmCodeList();
        List<Map<String, Object>> paramList = new ArrayList<>();

        for (String sysQmCode : sysQmCodeList) {
            char qmCodeNum = sysQmCode.charAt(sysQmCode.length() - 1);

            for (int i = 0; i < info.getMgrNum(); i++) {
                char qmNum = (char) (65 + i);
                Map<String, Object> msgMap = makeDefaultMap();
                msgMap.put("qm_code", sysQmCode);
                msgMap.put("queue_code", "MSG_" + getQmCodePre() + qmNum + "_" + qmCodeNum);
                msgMap.put("queue_name", "MSG_TO_" + info.getOrgBic() + qmNum);
                msgMap.put("queue_dtl_type", "MSG");
                msgMap.put("remote_qm_code", getQmCodePre() + qmNum);
                msgMap.put("remote_node_code", getNodeCode());
                msgMap.put("send_chl_name", "CCGW" + qmCodeNum + "." + info.getOrgBic() + qmNum);
                msgMap.put("remote_service_name", "CISD" + qmNum);
                paramList.add(msgMap);

                if (info.isDtt()) {
                    Map<String, Object> dttMap = makeDefaultMap();
                    dttMap.put("qm_code", sysQmCode);
                    dttMap.put("queue_code", "DTT_" + getQmCodePre() + qmNum + "_" + qmCodeNum);
                    dttMap.put("queue_name", "DTT_TO_" + info.getOrgBic() + qmNum);
                    dttMap.put("queue_dtl_type", "DTT");
                    dttMap.put("remote_qm_code", getQmCodePre() + qmNum);
                    dttMap.put("remote_node_code", getNodeCode());
                    dttMap.put("send_chl_name", "CCGW" + qmCodeNum + "." + info.getOrgBic() + qmNum);
                    dttMap.put("remote_service_name", "CISD" + qmNum);
                    paramList.add(dttMap);
                }
            }
        }

        return paramList;
    }

    @Override
    protected Map<String, Object> makeDefaultMap() {
        Map<String, Object> map = new LinkedHashMap<>();
        map.put("id", idMake());
        map.put("dc_code", getOrgInfo().getDcCode());
        map.put("qm_code", null);
        map.put("queue_code", null);
        map.put("queue_name", null);
        map.put("queue_type", "R");
        map.put("queue_dtl_type", null);
        map.put("node_type", "O");
        map.put("remote_qm_code", null);
        map.put("remote_node_code", null);
        map.put("remote_service_name", null);
        map.put("remote_ql_name", "MSG_CISD");
        map.put("send_chl_name", null);
        map.put("ext_param", null);
        map.put("status", "0");
        return map;
    }

    @Override
    protected String getTableName() {
        return "t_ccgw_q_conf";
    }
}
